package org.ruoyi;

import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;

public class Main {
    public static void main(String[] args) throws ExecutionException, InterruptedException, IOException {
//        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
//        String uri = "ws://localhost:8888/wss";
//        System.out.println("Connecting to " + uri);
//        try {
//            container.connectToServer(Device.class, URI.create(uri));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }


        // 创建 WebSocket 客户端
        StandardWebSocketClient webSocketClient = new StandardWebSocketClient();
        // 连接到 WebSocket 服务器
        ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(new VideoStreamHandler(), "ws://localhost:8888/wss");
        WebSocketSession webSocketSession = future.get();
//        webSocketSession.sendMessage(new TextMessage("start"));

//        for (int i = 0; i < 5; i++) {
//            // 发送消息
//            webSocketSession.sendMessage(new TextMessage(String.valueOf(i)));
//            // 等待一段时间
//            Thread.sleep(1000);
//            // 关闭连接
//        }
        while (true) {
            Scanner scanner = new Scanner(System.in);
            if (scanner.next() != null) {
                webSocketSession.close();
                break;
            }
        }

    }
}